package com.rabbitmq;

import com.rabbitmq.client.BuiltinExchangeType;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;

import java.io.IOException;
import java.util.concurrent.TimeoutException;

/**
 * 作者: LCG
 * 日期: 2019/9/18 09:27
 * 描述:
 */
public class TestRabbitMq {

    public static void main(String[] args) throws IOException, TimeoutException {

        ConnectionFactory connectionFactory=new ConnectionFactory();
        connectionFactory.setVirtualHost("/");
        connectionFactory.setPort(5672);
        connectionFactory.setUsername("zhangsan");
        connectionFactory.setPassword("zhangsan");
        connectionFactory.setHost("112.74.214.177");
        connectionFactory.setConnectionTimeout(6000);

        Connection connection = connectionFactory.newConnection();

        Channel channel = connection.createChannel();

        //创建交换机
         channel.exchangeDeclare("zhilian-exchange", BuiltinExchangeType.DIRECT,true);

         //创建队列
         channel.queueDeclare("zhilian-queue",true,false,false,null);

         //绑定交换机
         channel.queueBind("zhilian-queue","zhilian-exchange","test-key");



         //发送消息
         channel.basicPublish("zhilian-exchange","test-key",null,"hello !".getBytes());

         channel.close();

         connection.close();
    }

}
